module.exports = app => {
  const router = require('express').Router()
  const { generateOptions } = require('../../utils/index')
  const menu = require('../../models/menu')

  // 获取菜单
  router.get('/admin/api/rest/menu', async (req, res, next) => {
    try {
      let model = await menu.findAndCountAll()
      model.rows = generateOptions(model.rows)
      res.response(200, '查询成功', model)
    } catch (error) {
      next(error)
    }
  })


  // 获取菜单树
  router.get('/admin/api/admin/menuTree', async (req, res, next) => {
    try {
      const model = await menu.findAll({ where: { hidden: 0 }, attributes: ['path', 'menuName', 'icon', 'hidden', 'pid', 'id'] })
      const tree = generateOptions(model)
      res.response(200, '获取成功', tree)
    } catch (error) {
      next(error)
    }
  })




  app.use(router)
}